<template>
  <div>
    <!-- 按钮组 -->

    <div class="button-group">
      <el-button class="status-button" @click="myCouponsStatus(0)">待使用</el-button>
      <el-button class="status-button" @click="myCouponsStatus(1)">已使用</el-button>
      <el-button class="status-button" @click="myCouponsStatus(2)">已过期</el-button>
    </div>

    <div class="coupon-list">
      <div v-for="myCoupon in coupons" :key="myCoupon.couponId" class="coupon-item">
        <div class="coupon-header">
          <div class="coupon-label">
            <span>{{ myCoupon.couponName }}</span>
          </div>
          <div class="coupon-type">
            <span v-if="myCoupon.couponType === 1">满减</span>
            <span v-else-if="myCoupon.couponType === 2">折扣</span>
            <span v-else-if="myCoupon.couponType === 3">随机金额</span>
          </div>
        </div>
        <div class="coupon-body">
          <div class="coupon-value">
            <span>￥{{ myCoupon.discountPrice }}</span>
            <span v-if="myCoupon.couponType === 1">满{{ myCoupon.useThreshold }}元减{{ myCoupon.minusPrice }}元</span>
            <span v-else-if="myCoupon.couponType === 2">{{ myCoupon.discountNum }}折</span>
            <span v-else-if="myCoupon.couponType === 3">随机金额{{ myCoupon.minimumPrice }}至{{ myCoupon.maximumPrice }}元</span>
          </div>
          <div class="coupon-dates">
            <span>有效期: {{ myCoupon.effectiveStart }}至{{ myCoupon.effectiveEnd }}</span>
          </div>
          <div class="coupon-rules">
            <span v-if="myCoupon.applyStatus === 0">全部可用</span>
            <span v-else-if="myCoupon.applyStatus === 1">指定商品可用</span>
            <span v-else-if="myCoupon.applyStatus === 2">指定分类可用</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { myCoupon } from "@/api/coupon/coupon.js";

export default {
  name: "mycoupon",
  data() {
    return {
      coupons: [],
    };
  },
  methods: {
    myCouponsStatus(status) {
      myCoupon(status).then(res => {
        this.coupons = res.data;
      });
    },
  },
  created() {
    this.myCouponsStatus(0);
  },
};
</script>

<style scoped>

.button-group {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

.status-button {
  margin: 0 10px;
  padding: 10px 20px;
  font-size: 16px;
  border-radius: 10px;
  color: #fff;
  background: linear-gradient(90deg, #ff9a9e 0%, #fad0c4 99%, #fad0c4 100%);
  transition: background 0.3s ease;
}

.status-button:hover {
  background: linear-gradient(90deg, #ff6a88 0%, #ffc371 99%, #ffc371 100%);
}

@keyframes hoverEffect {
  0% {
    transform: translateY(0) scale(1);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  }
  50% {
    transform: translateY(-10px) scale(1.05);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
  }
  100% {
    transform: translateY(0) scale(1);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  }
}

.coupon-list {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  justify-content: center;
}

.coupon-item {
  background: linear-gradient(135deg, #ff6347, #ff8c00);
  border-radius: 20px;
  overflow: hidden;
  width: calc(33% - 40px);
  transition: all 0.3s ease;
  animation: hoverEffect 2s infinite;
}

.coupon-item:hover {
  transform: translateY(-15px) scale(1.1);
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.3);
}

.coupon-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-bottom: none;
}

.coupon-label {
  background-color: rgba(255, 255, 255, 0.2);
  color: #ffffff;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 16px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.coupon-type {
  background-color: rgba(0, 0, 0, 0.5);
  color: #ffffff;
  padding: 5px 15px;
  border-radius: 20px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.coupon-body {
  padding: 20px;
  color: #ffffff;
  text-align: center;
}

.coupon-value {
  font-size: 24px;
  font-weight: bold;
  margin-bottom: 15px;
}

.coupon-dates,
.coupon-rules {
  font-size: 16px;
  opacity: 0.8;
}
</style>
